Repository navigation
fix(agent-host): keep the Pi provider token out of the model's processes - #200
Merged
Merged
Conversation
With a key (--key, or the key option in process), a model request that does not carry it as a bearer token or an x-api-key is answered 401, without echoing what was sent. A test can then prove an agent sent the key it was given, not just some key. Without one, any key is taken, as before. Co-Authored-By: Claude Code <[email protected]>
A session bound to a provider profile passed the profile's token to Pi in CODEDECK_PI_PROVIDER_TOKEN, which the extension's registration named ($CODEDECK_PI_PROVIDER_TOKEN) so Pi read it per request. Everything Pi starts inherits its environment, so the model could print the token from its bash (reproduced live: `/tool node -p process.env.CODEDECK_PI_PROVIDER_TOKEN` printed it), as could background shells, sub-agents and MCP servers. Deleting the variable inside Pi is not enough: on Linux /proc/<pid>/environ keeps a process's starting environment, readable by any process of the same user. The token now never enters Pi's environment. The driver spawns Pi with a fourth stdio pipe (file descriptor 3), writes the token there and closes it; the extension reads it to the end as Pi loads it, before anything can start a process, and registers it as the profile's key, escaped so Pi's config syntax ($NAME, a leading !) takes it literally. Node passes a child only the stdio it is given, so no process Pi starts inherits the pipe. A sub-agent's Pi gets the token on its own pipe the same way. Without a token the profile is registered keyless and the extension says so on stderr; requests then fail for want of a key. The memory tool, which refused secret-named variables' values, now also refuses the token, since it is in no variable. The fake-model tests run the real Pi against a model server that requires the profile's token, which holds a leading ! and a $, and dump the environment of the model's shell, a background shell and a sub-agent's shell, and on Linux Pi's own /proc environ: none holds the token. Both tests fail with the token in Pi's environment; the /proc check fails when the extension deletes it at load instead. Co-Authored-By: Claude Code <[email protected]>
The token travels on its own pipe, not in Pi's environment, and why: what Pi starts inherits that environment, and Linux exposes a process's starting environment in /proc. An operator's own Pi wrapper must hand the pipe on. Co-Authored-By: Claude Code <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A Pi session bound to a provider profile no longer exposes the profile's token to anything the model starts.
The leak (reproduced live before the fix): the driver passed the token in
CODEDECK_PI_PROVIDER_TOKEN, which Pi read for every request. Pi's bash gets Pi's whole environment, so./codedeck live pi --fake-model --prompt "/tool node -p process.env.CODEDECK_PI_PROVIDER_TOKEN"printed the token. Background shells, sub-agents and MCP servers inherited it too.Why not just delete it inside Pi: on Linux,
/proc/<pid>/environkeeps a process's starting environment even afterdelete process.env.X— checked in anode:22-slimcontainer, where a child read the deleted value back from its parent. Any process of the same user (the model's bash) can read it.The route
The token never enters Pi's environment:
rpc.ts);apiKey, escaped so Pi's config syntax ($NAME, a leading!) takes it literally (extension/provider.ts);extension/task.ts);Without a token (a wrapper that doesn't hand fd 3 on), the profile is registered keyless, the extension writes a stderr line that the driver logs, and requests fail with Pi's "No API key" error.
Tests
piFakeModel.test.ts(the real Pi CLI, runs in CI): the fake model now requires the profile's token (--key), and the token holds a leading!and a$, so every turn proves Pi got the exact token through the escaping. Two new tests dump the environment of the model's shell, a background shell and a sub-agent's shell, plus Pi's own/procenviron on Linux, using shell builtins only. None holds the token./proccheck.configLiteral;readProviderToken; the keyless registration; memory refusing the token; the fake model's 401.Verified:
./codedeck check --changedgreen (host typecheck/test/build, Android); the Pi tests and fake-model tests on Linux (CODEDECK_ENGINE=docker), 155/155; live./codedeck live pi --fake-modelafter the fix: the variable printsundefined, and the fullexport -pdump does not contain the token.PowerShell (Windows) isn't tested separately. It runs with Pi's own environment, the same one as bash, and that environment no longer holds the token.
Traffic cost: none, nothing changes on the wire.
Data: nothing persisted changes.
🤖 Generated with Claude Code